// textareas.js
// Author: Nico Marrero
// Copyright 2012 Nico Marrero
//
//	 This file is part of django-serenity.
//
//    django-serenity is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    django-serenity is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with django-serenity.  If not, see <http://www.gnu.org/licenses/>.

function on_node_change(ed, cm, n, co)
{
    if( n.className == "mceItemVisualAid" ) {
        ed.dom.setAttrib(n, 'style', n.getAttribute('style'));
    }
}
function setup_tinymce(ed)
{
    ed.onNodeChange.add(on_node_change);
}
tinyMCE.init({
	mode : "specific_textareas",
	editor_deselector : /(mceNoEditor|mceEditorOff)/,
	theme : "advanced",
	element_format : "html",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	
	setup: setup_tinymce,

	theme_advanced_buttons1 : "fullscreen,|,newdocument,preview,save,tinyautosave,|,undo,redo,|,cut,copy,past,|,bullist,numlist,outdent,indent,|,link,unlink,anchor,image,media,|,code",
	theme_advanced_buttons2 : "styleprops,|,fontselect,fontsizeselect,formatselect,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull",
	theme_advanced_buttons3 : "tablecontrols,|,insertlayer,moveforward,movebackward,absolute,|,nonbreaking,|,hr,|,cleanup",
	auto_cleanup_word : true,
	
	plugins : "contextmenu, fullscreen, inlinepopups, layer, media, nonbreaking, paste, preview, save, searchreplace, style, table, tinyautosave, ",
	plugin_insertdate_dateFormat : "%m/%d/%Y",
	plugin_insertdate_timeFormat : "%H:%M:%S",
	tinyautosave_minlength : '10',
	valid_elements: '**',
	extended_valid_elements : "a[name|href|target=_blank|title|onclick],\
				   img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],\
				   hr[class|width|size|noshade],\
				   font[face|size|color|style],\
				   span[class|align|style]",
	table_default_border: '1',
	convert_urls: false,
	force_p_newlines: false,
	cleanup: false,
	verify_html : false,
	forced_root_block : false,
	remove_linebreaks : false,
	force_br_newlines : true,
	remove_trailing_nbsp : false,
	entity_encoding: "raw"
});

